package com.partsoft.dits.log;

/**
 * 日志级别
 */
public enum LogLevel {

	INFO("消息", 1),
	
	WARN("警告", 2),
	
	ERROR("错误", 3), 
	
	OTHER("其他", 9);
	
	private final int code;
	
	private final String title;
	
	private LogLevel(String title, int code) {
		this.code = code;
		this.title = title;
	}
	
	public String getTitle() {
		return title;
	}
	
	public int getCode() {
		return code;
	}
	
	@Override
	public String toString() {
		return getTitle();
	}
	
	public static final LogLevel fromCode(int code) {
		for (LogLevel level : LogLevel.values()) {
			if (level.getCode() == code) return level;
		}
		return OTHER;
	}
	
	public static LogLevel fromName(String name) {
		for (LogLevel value : LogLevel.values()) {
			if (value.name().equalsIgnoreCase(name)) return value;
		}
		return OTHER;
	}


}
